package org.dept.controller;

import org.dept.pojo.Dept;
import org.dept.service.DeptClientService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class FeignController {
    //理解：消费者，不应该有service层
    //RestTemplate供我们直接调用，注册到spring中
    //(url,Class<T> responseType)
    //@Resource
    //private RestTemplate restTemplate;//提供多种便捷访问远程http服务的方法，简单的restful服务模板
    //这里地址一个是一个变量，通过服务名来访问
    //private static final String REST_URL_PREFIX="http://localhost:8081";
    //private static final String REST_URL_PREFIX="http://PROVIDER-DEPT";

    @Resource
    private DeptClientService service=null;

    @RequestMapping("/consumer/dept/add")
    public Integer add(Dept dept){
        //System.out.println(dept.getName());
        //return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Integer.class);
        return this.service.addDept(dept);
    }

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable("id") int id){
        //return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,Dept.class);
        return this.service.select(id);
    }

    @RequestMapping("/consumer/dept/dList")
    public List<Dept> dList(){
        //return restTemplate.getForObject(REST_URL_PREFIX+"/dept/dList",List.class);
        return this.service.dList();
    }

}
